# -*- coding: utf-8 -*- 
# @Time : 2020/4/25 23:27 
# @Author : ganwei 
# @File : 101.py
# @desc : leetcode 101 对称二叉树

"""
解决方案1
"""
class TreeNode(object):
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None

class Solution(object):
    def isSymmetric(self, root):
        """
        :type root: TreeNode
        :rtype: bool
        """
        return self.viewtree(root.left,root.right)

    def viewtree(self,p,q):
        if p != None and q != None and p.val != q.val:
            return False
        elif p == None and q == None:
            return True
        elif p == None and q != None:
            return False
        elif p != None and q == None:
            return False
        return self.viewtree(p.left,q.right) and self.viewtree(p.right,q.left)


"""
解决方案1-递归
"""
def solution(p, q):
    if p != None and q != None and p.val != q.val:
        return False
    elif p == None and q == None:
        return True
    elif p == None and q != None:
        return False
    elif p != None and q == None:
        return False
    return solution(p.left,q.right) and solution(p.right,q.left)

"""
主函数
"""
if __name__ == "__main__":
    print("hello")
    head = TreeNode(1)
    left = TreeNode(2)
    right = TreeNode(2)
    t1 = TreeNode(3)
    t2 = TreeNode(4)
    t3 = TreeNode(4)
    t4 = TreeNode(3)
    head.left = left
    head.right = right
    left.left = t1
    left.right = t2
    right.left = t3
    right.right = t4
    ss = Solution()
    print(ss.isSymmetric(head))
    #print(solution(head.left,head.right))